Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | 5x 5x 5x 5x 5x 1x 4x 5x 5x 5x 5x 4x 4x 4x 4x 1x 3x 1x 1x 2x 4x 4x 4x 1x 2x 2x 2x 2x 2x 1x 1x | import { fetchSuccessStoryBySlug } from "@/data/loaders";
import SuccessStoryClient from "./SuccessStoryClient";
import { generateMetadataObject } from '@/lib/metadata';
import fetchContentType from '@/lib/strapi/fetchContentType';
import { strapiImage } from '@/lib/strapi/strapiImage';
import { Metadata } from "next";
import { generateCombinedOgImage } from '@/lib/strapi/generateOgImage';
interface PageProps {
params: Promise<{ slug: string }>;
}
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
const BASE_URL_NEXT = process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3000";
const resolveParams = await params;
const slug = await resolveParams?.slug;
const pageData = await fetchContentType('success-stories', {
filters: { slug: slug }, // Filter by slug
populate: ["seo.metaImage","logo"],
}, true)
//console.log("Page Data:", pageData); // Debugging output
if (!pageData) {
return {
title: "Story Not Found | Bitmutex Technologies",
description: "The requested story does not exist. Browse more stories by Bitmutex Technologies.",
robots: "noindex, nofollow", // Avoid indexing non-existent pages
};
}
const seo = pageData?.seo;
const metadata = generateMetadataObject(seo);
// ✅ Ensure title fallback to `pageData.title` if `seo.metaTitle` is missing
const seotitle = seo?.metaTitle
? `${seo.metaTitle} | Success Stories with Bitmutex`
: `${pageData.name || "Untitled"} | Success Stories with Bitmutex`;
// ✅ Use pageData description as fallback if metaDescription is not available
let seodescription = seo?.metaDescription || `How ${pageData.name} succeeded with Bitmutex - ${pageData.content || ""}`;
Iif (seodescription.length > 150) {
seodescription = seodescription.substring(0, seodescription.lastIndexOf(" ", 150)) + "...";
}
// ✅ Override normal title field
metadata.title = seotitle;
metadata.description = seodescription;
// If seo.metaImage exists, use it. Otherwise, if logo exists, generate a combined image.
let ogImages: { url: string }[] = [];
if (seo?.metaImage) {
ogImages = [{ url: strapiImage(seo.metaImage.url) }];
} else if (pageData?.logo) {
// Generate a combined image using our utility function.
const generatedImageUrl = await generateCombinedOgImage(strapiImage(pageData.logo.url), slug, BASE_URL_NEXT);
ogImages = [{ url: generatedImageUrl }];
} else {
ogImages = [];
}
// ✅ Override OG fields
metadata.openGraph = {
...(metadata.openGraph as any), // Cast to 'any' to allow unknown properties
title: seotitle,
description: seodescription,
images: ogImages,
url: `${BASE_URL_NEXT}/success-stories/${slug}`, // Add custom URL field
site_name: "Bitmutex",
locale: "en_US",
type: "article",
};
// ✅ Assign canonical URL to `alternates`
metadata.alternates = {
canonical: `${BASE_URL_NEXT}/success-stories/${slug}`,
};
return metadata;
}
// Fetch data on the server
const fetchData = async (slug: string) => {
return await fetchSuccessStoryBySlug(slug);
};
export default async function SuccessStoryDetails({ params }: PageProps) {
const resolveParams = await params;
const slug = resolveParams?.slug;
const story = await fetchData(slug);
if (!story) {
return <p className="text-center text-gray-500 mt-10">Success story not found.</p>;
}
return <SuccessStoryClient story={story} />;
}
|